#include "stdio.h"
#include "unistd.h"
#include "sys/types.h"
#include "sys/stat.h"
#include "fcntl.h"
#include "stdlib.h"
#include "string.h"
#include <poll.h>
#include <sys/select.h>
#include <sys/time.h>
#include <signal.h>
#include <fcntl.h>
#include <linux/input.h>

static struct input_event inputevent;


int main(int argc, char *argv[]){
	int fd;
	int err = 0;
	char *filename;

	filename = argv[1];

	if (argc !=2 )
	{
		printf("Error Usage!\r\n");
		return -1;
	}

	fd = open(filename, O_RDWR);
	if (fd <0)
	{
		printf("Can't open file %s \r\n", filename);
		return -1;
	}

	while(1){
		err = read(fd, &inputevent, sizeof(inputevent));
		if (err >0)
		{
			switch (inputevent.type)
			{
				case EV_KEY:
					if (inputevent.code < BTN_MISC)
					{
						printf("key %d %s \r\n",inputevent.code,
								inputevent.value ? "press" : "release");
					}
					break;
				
				default:
					break;
			}
		}else {
			printf("读取数据失败\r\n");
		}
	}
	return 0;
}
